#!/usr/bin/env python
# coding: utf-8
#学生管理系统
#学生成绩管理系统
# In[ ]:


class Student:
    def __init__(self, name, id, course, score):
        self.name = name
        self.id = id
        self.course = course
        self.score = score


students = []


def print_menu():
    print("=" * 30)
    print("欢迎使用学生成绩管理系统")
    print("=" * 30)
    print("请选择操作：")
    print("1. 记录学生成绩")
    print("2. 查询学生成绩")
    print("3. 统计课程成绩")
    print("4. 退出系统")


def record_score():
    print("====== 记录学生成绩 ======")
    name = input("请输入学生姓名：")
    id_num = input("请输入学生学号：")
    course = input("请输入课程名称：")
    while True:
        try:
            score = float(input("请输入成绩（0-100）："))
            if 0 <= score <= 100:
                break
            print("成绩必须在0到100之间，请重新输入。")
        except ValueError:
            print("输入无效，请输入一个有效的数字。")
    student = Student(name, id_num, course, score)
    students.append(student)
    print("成绩已成功记录！")


def query_score():
    print("请选择查询方式：")
    print("1. 按学生姓名查询")
    print("2. 按学生学号查询")
    print("3. 按课程名称查询")
    choice = input("请输入选项序号：")
    if choice == "1":
        name = input("请输入学生姓名：")
        found = False
        for student in students:
            if student.name == name:
                print(f"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}")
                found = True
        if not found:
            print("未找到该学生的成绩记录。")
    elif choice == "2":
        id_num = input("请输入学生学号：")
        found = False
        for student in students:
            if student.id == id_num:
                print(f"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}")
                found = True
        if not found:
            print("未找到该学生的成绩记录。")
    elif choice == "3":
        course = input("请输入课程名称：")
        found = False
        for student in students:
            if student.course == course:
                print(f"姓名: {student.name}, 学号: {student.id}, 课程: {student.course}, 成绩: {student.score}")
                found = True
        if not found:
            print("未找到该课程的成绩记录。")
    else:
        print("无效的选项，请重新输入。")


def statistics_score():
    print("====== 统计课程成绩 ======")
    course = input("请输入课程名称：")
    scores = [student.score for student in students if student.course == course]
    if scores:
        average = sum(scores) / len(scores)
        highest = max(scores)
        lowest = min(scores)
        print(f"课程: {course}")
        print(f"平均分: {average:.2f}")
        print(f"最高分: {highest}")
        print(f"最低分: {lowest}")
    else:
        print("未找到该课程的成绩记录。")


def exit_system():
    print("感谢使用学生成绩管理系统，再见！")
    exit()


while True:
    print_menu()
    choice = input("请输入选项序号：")
    if choice == "1":
        record_score()
    elif choice == "2":
        query_score()
    elif choice == "3":
        statistics_score()
    elif choice == "4":
        exit_system()
    else:
        print("无效的选项，请重新输入。")


# In[ ]:




